/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ftpcombiner.gui.applicationframe.framesplitter.filetree;

import ftpcombiner.gui.GUIResources;
import ftpcombiner.server.virtualfiles.VirtualFile;
import java.awt.Color;
import java.awt.Component;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JTree;
import javax.swing.tree.TreeCellRenderer;

/**
 *
 * @author Ben
 */
public class FileTreeRenderer implements TreeCellRenderer {

    JLabel renderer;

    public FileTreeRenderer() {
        renderer = new JLabel();
    }

    @Override
    public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
        renderer.setText(value.toString());
        if (selected) {
            renderer.setBackground(new Color(204, 204, 204));
        } else {
            renderer.setBackground(Color.WHITE);
        }
        if (leaf) {
            if (value instanceof VirtualFile) {
                renderer.setIcon(GUIResources.getInstance().getFileIcon());
            } else if (value instanceof String) {
                ImageIcon icon = GUIResources.getInstance().getLoadingIcon();
                //icon.setImageObserver(tree);
                renderer.setIcon(icon);
                //System.out.println("icon: "+GUIResources.getInstance().getLoadingIcon());
            }
        } else {
            renderer.setIcon(GUIResources.getInstance().getFolderIcon());
        }
        return renderer;
    }
}
